using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GameEditor.Common.InternalDialogs
{
    internal partial class FindTextDialog : Form
    {
        public FindTextDialog()
        {
            InitializeComponent();
            
        }
        private OnFindNextText findNextTextCallback = null;
        private FindTextFlags flags;

        public void Show(IWin32Window owner, string text, FindTextFlags flags, OnFindNextText findNextTextCallback)
        {
            gbDirection.Visible = (flags & FindTextFlags.NoUpDown) == 0;
            cbMatchCase.Checked = (flags & FindTextFlags.MatchCase) != 0;
            cbMatchCase.Visible = (flags & FindTextFlags.HideMatchCase) == 0;
            cbMatchWholeWord.Checked = (flags & FindTextFlags.MatchWholeWord) != 0;
            cbMatchWholeWord.Visible = (flags & FindTextFlags.HideMatchWholeWord) == 0;
            rbDown.Checked = (flags & FindTextFlags.Down) != 0;
            tbText.Text = text;
            this.flags = flags;
            this.findNextTextCallback = findNextTextCallback;

            this.Show(owner);
        }

        private void OnFindNext(object sender, EventArgs e)
        {
            if (findNextTextCallback != null)
            {
                FindTextData data = new FindTextData();
                data.flags = flags;
                data.direction = rbUp.Checked ? FindTextDirection.Up : FindTextDirection.Down;
                data.matchCase = cbMatchCase.Checked;
                data.matchWholeWord = cbMatchWholeWord.Checked;
                data.text = tbText.Text;
                findNextTextCallback(data);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }


    }
}

namespace GameEditor.Common
{
    [Flags]
    public enum FindTextFlags
    {
        Default = 0,
        MatchWholeWord = 1,
        MatchCase = 2,
        HideMatchWholeWord = 4,
        HideMatchCase = 8,
        NoUpDown = 16,
        Down = 32
    }
    public enum FindTextDirection
    {
        Up,
        Down
    }
    public class FindTextData
    {
        internal string text;
        internal bool matchWholeWord;
        internal bool matchCase;
        internal FindTextDirection direction;
        internal FindTextFlags flags;

        public FindTextFlags Flags
        {
            get { return flags; }
        }

        public FindTextDirection Direction
        {
            get { return direction; }
        }

        public bool MatchCase
        {
            get { return matchCase; }
        }

        public bool MatchWholeWord
        {
            get { return matchWholeWord; }
        }

        public string Text
        {
            get { return text; }
        }

    }
    public delegate void OnFindNextText(FindTextData data);

}

